# @Time    : 2018/6/6 11:04
# @Author  : Jame
from conf import setting
import json,os,pickle


def select(name):
    path_dir=os.path.join(setting.CONSUMER_DIR,name) #每个用户的家目录地址consumer/jame/
    path=os.path.join(path_dir,name) #db/jame/jame.json存在
    if os.path.exists(path):
        with open(path,'rb') as f:
            return pickle.load(f)
    else:
        return False #表示没注册



def save(obj):
    path=os.path.join(setting.CONSUMER_DIR,obj.name) #consumer/jame/
    if not os.path.exists(path):
        os.mkdir(path)

    path_file=os.path.join(path,obj.name) #consumer/jame/jame.json obj.name为每个对象的名字
    with open(path_file,'wb') as f:
        pickle.dump(obj,f)
        f.flush()
